package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShoppingCartMapper {
    //查询购物车有没有添加过这个菜品
    ShoppingCart findShoppingCart(ShoppingCart shoppingCart);
    //添加过则修改数量number
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    Integer updateNumber(@Param("id") Long id, @Param("number") Integer number);
    //没有则新增
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId}," +
            "#{dishFlavor},#{number},#{amount},#{createTime})")
    Integer save(ShoppingCart shoppingCart);

    //查看购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> findAll(Long userId);

    //清空
    @Delete("delete from shoppinG_cart where user_id = #{userId}")
    Integer deleteByUserId(Long userId);


    //减号(更新number)
    Integer updateNumber2(ShoppingCart shoppingCart);
    //删除一条
    Integer delete(ShoppingCart shoppingCart);
}
